<template>
  <div>
    <el-card style="width: 40%; margin: 10px auto">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="姓名">
          <el-input v-model="form.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="用户角色">
          <el-input v-model="form.type" disabled></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" show-password></el-input>
        </el-form-item>
        （还有点之后加
      </el-form>
      <div style="text-align: center">
        <el-button type="primary" @click="update">保存</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "PersonView",
  data() {
    return {
      form: {}
    }
  },
  created() {
    let str = sessionStorage.getItem("user") || "{}"
    this.form = JSON.parse(str)
  },
  // to do:把这个更新个人信息的接口搞搞
  methods :{
    update() {
      request.put("http://124.70.179.188:8082/api/user", this.form).then(res => {
        console.log(res)
        if (res.code === '0'){
          this.$message({
            type:"success",
            message:"更新成功"
          })
          sessionStorage.setItem("user",JSON.stringify(this.form))
        } else {
          this.$message({
            type:"error",
            message: res.msg
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>